package com.ynu.appuser.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ynu.appuser.domain.appuser.MdUser;
import com.ynu.appuser.domain.physical.BloodOxygen;
import com.ynu.appuser.service.IMdUserService;
import com.ynu.appuser.service.IPhysicalDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用作操作体征数据，因为医生端5种数据是连体的，所以就放一起了
 *
 * @author tangzheng
 * @date 2022-12-15
 */
@RestController
@RequestMapping("/appuser/physical")
public class PhysicalDataController extends BaseController {

    @Autowired
    private IMdUserService mdUserService;
    @Autowired
    private IPhysicalDataService physicalDataService;

    /**
     * 查询App用户列表和体征数据
     */
    @PreAuthorize("@ss.hasPermi('appuser:score:list')")
    @GetMapping("/listUserAndData")
    public TableDataInfo list(MdUser mdUser, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime) {
        startPage();
        List<MdUser> list = mdUserService.selectListUserAndData(mdUser, startTime);
        return getDataTable(list);
    }


    /**
     * 查某一类数据
     *
     * @param username  appuser账户名
     * @param startTime 数据开始时间
     * @param dataType  指定查询的是哪一类数据
     * @return 血氧列表
     */
    @PreAuthorize("@ss.hasPermi('appuser:score:list')")
    @GetMapping("/specificData")
    public AjaxResult specificData(String username, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime, String dataType) {
        List<BloodOxygen> list = new ArrayList<>();
        switch (dataType) {
            case "bloodOxygen":
                list = physicalDataService.selectListBloodOxygen(username, startTime);
                break;
            case "heartrate":
                list = physicalDataService.selectListHeartrate(username, startTime);
                break;
            case "sleep":
                list = physicalDataService.selectListSleep(username, startTime);
                break;
            case "stepCount":
                list = physicalDataService.selectListStepCount(username, startTime);
                break;
            case "bloodPressure":
                list = physicalDataService.selectListBloodPressure(username, startTime);
                break;
            default:
                break;
        }
        return AjaxResult.success(list);
    }
}
